// // Copyright (c) 2009 All Right Reserved // // Stephen Toub // stoub@microsoft.com // 2009-01-01 // Contains ... // Classes for interop with Win32 MCI and low-level MIDI API using System; namespace LargoCommon.Midi { /// Represents a safe handle to a MIDI device. public sealed class MidiDeviceHandle : IDisposable { #region Fields /// Whether the handle has been disposed. private bool isDisposed; //// = false; #endregion #region Constructors /// Initializes a new instance of the MidiDeviceHandle class. /// The handle to the MIDI device. public MidiDeviceHandle(int handle) { // Store the handle this.Handle = handle; } /// /// Finalizes an instance of the MidiDeviceHandle class. /// ~MidiDeviceHandle() { this.DisposeDevice(); //// false } #endregion #region Properties /// Gets the underlying handle. /// General musical property. public int Handle { get; private set; } /// Gets a value indicating whether the handle is active and open. /// General musical property. public bool IsOpen => this.Handle != 0; #endregion /// Dispose of the handle. public void Dispose() { this.DisposeDevice(); //// true //// FxCop GC.SuppressFinalize(this); } #region Closing the Handle /// Closes the handle. private void Close() { // If the handle is open, close it and mark it as such. if (!this.IsOpen) { return; } MidiInternalDevices.CloseMidiOut(this.Handle); this.Handle = 0; } #endregion /// Dispose of the handle. private void DisposeDevice() { //// bool disposing // If not yet disposed if (this.isDisposed) { return; } // Close the handle and mark us as having been disposed this.Close(); this.isDisposed = true; //// FxCop: if (disposing) { GC.SuppressFinalize(this); } } } }